package com.bw.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.bw.pojo.business.Activity;
import com.bw.pojo.business.Ad;
import com.bw.pojo.goods.Sku;
import com.bw.pojo.goods.Spu;
import com.bw.service.business.ActivityService;
import com.bw.service.business.AdService;
import com.bw.service.goods.CategoryService;
import com.bw.service.goods.SkuSearchService;
import com.bw.service.goods.SkuService;
import com.bw.service.goods.SpuService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class indexController {

    @Reference
    private AdService adService;

    @Reference
    private CategoryService categoryService;

    @Reference
    private SkuService skuService;

    @Reference
    private SkuSearchService skuSearchService;

    @GetMapping("/index")
    public String index(Model model){

        //index_lb 首页轮播图
        //index_amusing 有趣区
        //index_ea_lb 家用电器楼层轮播图
        //index_ea 家用电器楼层广告
        //index_mobile_lb 手机通讯楼层轮播图
        //index_mobile 手机通讯楼层广告

        //查询首页轮播图
        List<Ad> index_lb = adService.findByPosition("web_index_lb");
        model.addAttribute("lbt",index_lb);
        //手机通讯楼层轮播图
        List<Ad> index_lb_phone = adService.findByPosition("index_mobile_lb");
        model.addAttribute("phone",index_lb_phone);
        //家用电器楼层轮播图
        List<Ad> index_lb_tv = adService.findByPosition("index_ea_lb");
        model.addAttribute("tv",index_lb_tv);

        //新闻
        List<Ad> index_news=adService.findByPosition("web_index_news");
        model.addAttribute("news",index_news);

        List<Ad> index_phone=adService.findByPosition("index_goods");
        model.addAttribute("ph",index_phone);
        List<Ad> index_tv=adService.findByPosition("index_favorite");
        model.addAttribute("tvv",index_tv);

        //商品分类
        List<Map> categoryList = categoryService.findCategoryTree();
        model.addAttribute("categoryList",categoryList);

        //排行
        List<Sku> skuList = skuService.sampleList(4);
        model.addAttribute("sku",skuList);
        List<Sku> skuList2 = skuService.sampleList(4);
        model.addAttribute("sku2",skuList2);
        List<Sku> skuList3 = skuService.sampleList(4);
        model.addAttribute("sku3",skuList3);

        //猜你喜欢
        List<Sku> favoriteList = skuService.sampleList(6);
        model.addAttribute("like",favoriteList);

        return "index";
    }
}
